package cn.zyy.jdbc;

import cn.zyy.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo05 {
    public static void main(String[] args) {
        Connection conn = JDBCUtil.getConnection();
        String sql = "insert into usr(username,password,birth,create_time) values(?,?,?,?)";
        PreparedStatement pstmt = null;
        try {
            pstmt= conn.prepareStatement(sql);
            pstmt.setString(1,"王五");
            pstmt.setString(2,"123456");
//            Date date = new Date(new java.util.Date().getTime());
//            pstmt.setDate(3,date);
            pstmt.setObject(3, "1991-12-03");
            pstmt.setString(4,"2022-02-11 11:36:15");
            int i = pstmt.executeUpdate();
            System.out.println("i = " + i);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtil.closeAll(null,pstmt,conn);
        }
    }
}
